import { appDescription } from "./src/constants/index";
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import env from "./src/constants/env";
export default defineNuxtConfig({
  srcDir: "src/",
  loading: false,
  modules: [
    "@nuxtjs/tailwindcss",
    "@vueuse/nuxt",
    "@pinia/nuxt",
    "@pinia-plugin-persistedstate/nuxt",
    "@nuxtjs/color-mode",
    "@element-plus/nuxt",
    "@nuxtjs/i18n",
  ],
  plugins: [
  ],
  runtimeConfig: {
    // 服务端
    username: "admin",
    // 客户端 + 服务端
    public: {
      globalAPI: env[process.env.ENV], // 配置对象
    },
  },
  // experimental: {
  // when using generate, payload js assets included in sw precache manifest
  // but missing on offline, disabling extraction it until fixed
  // payloadExtraction: false,
  // renderJsonPayloads: true,
  // typedPages: true,
  // },
  css: [
      "element-plus/dist/index.css",
      "element-plus/theme-chalk/display.css",
      "~/assets/styles/base.css",
  ],
  i18n: {
    strategy: 'no_prefix', // 添加路由前缀的方式
    locales: ["en","zh"], //配置语种
    defaultLocale: 'zh', // 默认语种
    vueI18n: './locales/config.js', // 通过vueI18n配置
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'language', // 自定义本地存储键名
      cookieOptions: {
        maxAge: 60 * 60 * 24 * 30, // 30 天
        path: '/',
      },
    },
  },
  colorMode: {
    classSuffix: "", // 设置css前缀
  },
  nitro: {
    // 代理配置 未测试
    devProxy: {
      '/api': {
        target: 'http://apis.juhe.cn',
        changeOrigin: true
      }
    },
    esbuild: {
      options: {
        target: "esnext",
        minify: true, // 开启压缩
        terserOptions: {
          compress: {
            drop_console: true, // 移除 console.log
          },
        },
      },
    },
    prerender: {
      crawlLinks: false,
      routes: ["/"], // 预先渲染的页面
      ignore: [], // 排除预渲染
    },
  },
  app: {
    // seo 相关设置html head 部分
    head: {
      viewport: "width=device-width,initial-scale=1",
      // link: [{ rel: "icon", href: "/favicon.ico", sizes: "any" }],
      link: [{ rel: "icon", href: "/public/vite.png", sizes: "any" }],
      meta: [
        { name: "viewport", content: "width=device-width, initial-scale=1" },
        { name: "description", content: appDescription },
        {
          name: "apple-mobile-web-app-status-bar-style",
          content: "black-translucent",
        },
        {
          name: "theme-color",
          media: "(prefers-color-scheme: light)",
          content: "white",
        },
        {
          name: "theme-color",
          media: "(prefers-color-scheme: dark)",
          content: "#222222",
        },
      ],
    },
  },
  vite: {
    logLevel: 'info',
    server: {
      hmr: true,
      watch: {
        usePolling: true //set here to enable hot reload
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@import "@/assets/styles/variables.scss";', // 设置sass变量
        },
      },
    },
    plugins: [
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    ssr: {
      noExternal: ['element-plus'],
    },
    optimizeDeps: {
      include: ['vue', 'pinia']
    },
    build: {
      sourcemap: false, // 禁用源映射文件的生成
    },
  },
  build:{
    transpile: ['element-plus'], // 后续添加
  },
  devtools: {
    enabled: false,
  },
  features: {},
  future: {
    compatibilityVersion: 4,
  },
  compat: {
    compatibilityDate: "2024-08-06",
  },
  sourcemap: {
    server: false,
    client: true,
  },
  buildOptions: {
    // Disable source maps for production builds
    productionSourceMap: false,
    // Disable source maps for development builds
    devtools: false,
  }
});
